package stackSinglyLinkListOperation;

import binaryTreePackage.BSTNode;

public class Linklist {
	public Linklist() {
		/*------------------------------------------------------
		 * Constructor, initialize the head Node of the Linklist
		 ------------------------------------------------------*/
		this.node = null;
		this.Next = null;
	}
public boolean isEmpty(){
	if(this.node==null)
		return true;
	else
		return false;
}
	// Being test
	public Linklist getTopNode(Linklist currentTop) {
		/*---------------------------------------------
		 * Check whether Stack is empty by check the top
		 * node of data in linklist is NULL or not 
		 ---------------------------------------------*/
		if (currentTop.getNode() == null) {
			
			// Warning message
			System.out.println("This Stack is empty");
			// maintain currentHead
			return null;
		} else {
			/*-----------------------------------------------------
			 * THE FOLLOW METHOD IS USED WHEN NEED TO
			 * RETURN DATA IN THE TOP NODE
			 *            currentTop.getData();
			 ------------------------------------------------------*/
			return currentTop;
			}
		}
	

	// Save data in the node by using function, instead of directly access
	public void saveNode(BSTNode node) {
		this.node=node;
	}

	/*------------------------------------------------------------------------
	 * Get node's data function,it can be used to get any node's data within
	 * specific function
	 -------------------------------------------------------------------------*/
	public BSTNode getNode() {
		// Get this node's data
		return this.node;
	}

	/*--------------------------------------------------------------------------
	 * InsertNode Function, every newNode is insert in the linklist to be the 
	 * new head node of the link list , and finally return the newNode's object
	 * to replace the old head's object which save in the currentHead valuable.
	 ---------------------------------------------------------------------------*/

	public Linklist insertNode(Linklist head, BSTNode node) {
		// Create a new node
		Linklist newNode = new Linklist();
		// Save data in the new node
		newNode.saveNode(node);
		// New node become the new head of the linklist
		// In this expression,the "head" is previous head of
		// linklist
		newNode.Next = head;
		return newNode;
		}

	/*--------------------------------------------------------------------------------------------
	 * Show all data in the linklist with counting numbers
	 --------------------------------------------------------------------------------------------*/


	// Parameters, need to use the provided function to access.
	private BSTNode node;;
	public Linklist Next;
}
